package com.koron.css2.newProjectCenter.impl;


import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.mapper.PjInstallUserMapper;
import com.koron.css2.newProjectCenter.vo.PjInstallUserVo;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.Tools;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class PjInstallUserList implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {

			Map<String, String> param = JsonUtils.objectToPojo(req.getData(), Map.class);
			PjInstallUserMapper mapper = factory.getMapper(PjInstallUserMapper.class);
			List<String> arrbillNo = Arrays.asList(param.get("arrbillNo").split(","));
			List<PjInstallUserVo> list = mapper.selectList(arrbillNo);
			Map<String, String> MMT = Tools.mapDicByCode(factory, "MMT");//水表分类
			Map<String, String> CMC = Tools.mapDicByCode(factory, "CMC");//水表用途
			Map<String, String> UWS = Tools.mapDicByCode(factory, "UWS");//用水对象
			for(PjInstallUserVo bean:list) {
				//转换数据字典
				bean.setMeterType(MMT.get(bean.getMeterType()));
				bean.setMeterUse(CMC.get(bean.getMeterUse()));
				bean.setUsemeterObject(UWS.get(bean.getUsemeterObject()));
			}
			MessageBean<List> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", List.class);
			info.setData(list);
			return info;
		}catch(Exception e){
			logger.error("水表立户列表查询失败"+e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败", null);
		}
	}

}
